<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title><%= title %> - <%= desc %></title>

  <script src="https://unpkg.com/vue@2.6.10/dist/vue.js"></script>
  <script src="https://unpkg.com/axios@0.19.0/dist/axios.min.js"></script>
  <link rel="stylesheet" href="/css/reset.css">
  <link rel="stylesheet" href="/css/index.css">
</head>
<body>
  <div id="app" class="page-index">
    <div class="title">
      <div class="inner-box">
        <h2><%= title %></h2>
        <p class="desc"><%= desc %></p>
      </div>
    </div>

    <div class="login-positioning">
      <div class="login-container">
        <h3>开始使用</h3>
  
        <div class="content">
          <!-- <p class="content-title">E-mail</p> -->
          <div class="email-input">
            <input type="text" v-model="email" placeholder="请输入Email地址"
              @keyup.enter="submit">
          </div>
          <div class="content-actions">
            <div class="btn-submit"
              :class="{
                ready: email
              }"
              @click="submit">
              开启优雅的工作
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>

  <script src="/js/query.js"></script>
  <script src="/js/api/user.js"></script>
  <script>
    const _app = new Vue({
      el: '#app',
      data: {
        email: '',
        errorMessage: '',
      },
      mounted() {
      },
      methods: {
        submit() {
          if (!this.email) {
            alert('请先填写Email')
            return
          }

          const nickname = this.email.split('@')[0]
          const email = this.email

          loginWithEmail(email, nickname).then(res => {
            console.log(res)
            location.href = '/upload'
          }).catch(err => {
            console.log(err)
            alert(err.message)
          })
        }
      },
    })
  </script>
</body>
</html>